<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

class CustomerLogOperate extends Model
{
    public bool $timestamps = false;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'customer_log_operate';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [
        'id', 'module', 'action', 'params', 'ip', 'http_method', 'http_code', 'start_at', 'time_token', 'creator_id', 'created_at',
    ];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = [];


    protected function getTimeTakenAttribute($value): string
    {
        return $value > 1000 ? intval($value/1000) . 's' : $value . 'ms';
    }

    public function creator(){
        return $this->hasOne(CustomerAdmin::class, "id", "creator_id");
    }
}
